﻿using System;
using System.Collections.Generic;
using WindowsGame.Data;
using WindowsGame.Library.Data;
using WindowsGame.Library.ProxyObjects;

namespace WindowsGame.Manager
{
	public interface IDataManager
	{
		AllData LoadData(String fldr, String[] files);
	}

	public class DataManager : IDataManager
	{
		private IFileManager fileManager;
		private ProxyObjectBuilder proxyObjectBuilder;

		public DataManager(IFileManager fileManager, ProxyObjectBuilder proxyObjectBuilder)
		{
			this.fileManager = fileManager;
			this.proxyObjectBuilder = proxyObjectBuilder;
		}

		public AllData LoadData(String fldr, String[] files)
		{
			// Load offsets data.
			String offsetsFile = files[0];
			var offsets = fileManager.LoadXml<OffsetData[]>(offsetsFile);

			// Load XML data.
			String spaceshipsFile	= files[1];
			String weaponsFile		= files[2];
			String[] xmlFiles = new[] { spaceshipsFile, weaponsFile };
			proxyObjectBuilder.BuildProxyObjects(fldr, xmlFiles);

			// Load TXT data.
			String spaceshipFile	= files[3];
			String weaponFile		= files[4];
			IList<String> spaceshipList = fileManager.LoadTxt(spaceshipFile);
			IList<String> weaponList = fileManager.LoadTxt(weaponFile);

			return new AllData(offsets, spaceshipList, weaponList);
		}

	}
}